package com.easystudy.media.conf;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import com.easystudy.media.service.MediaService;
import com.easystudy.media.service.impl.MediaServiceImpl;

/**
 * @文件名称: AutoConfig.java
 * @功能描述: 自动导入配置类
 * @版权信息: www.easystudy.com
 * @技术交流: 961179337(QQ群)
 * @编写作者: lixx2048@163.com
 * @联系方式: 941415509(QQ)
 * @开发日期: 2021年6月7日
 * @历史版本: V1.0 
 * @备注信息:
 */
@Configurable
@Import(MediaConfig.class)
@ConditionalOnWebApplication
@ConditionalOnClass(MediaService.class)
@ComponentScan("com.easystudy.media")
public class AutoConfig {	
	@Bean
	@ConditionalOnMissingBean
    public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
        return new RestTemplate(factory);
    }
	
	@Bean
	@ConditionalOnMissingBean
    public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setReadTimeout(120000);
        factory.setConnectTimeout(15000);
        return factory;
    }
	
	@Bean					
	@ConditionalOnMissingBean
	public MediaService jsdService() {
		return new MediaServiceImpl();
	}
}